package logic

import (
	"context"
	"store/model/redis"

	"store/storerpc/internal/svc"
	"store/storerpc/storerpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CollectlistLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCollectlistLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CollectlistLogic {
	return &CollectlistLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CollectlistLogic) Collectlist(in *storerpc.CollectlistRequest) (*storerpc.CollectlistResponse, error) {
	// todo: add your logic here and delete this line

	scores := redis.Client.ZRevRangeWithScores("collectlist", 0, 9)
	var liststruct []*storerpc.CollectStruct
	for _, lists := range scores.Val() {
		Collect := &storerpc.CollectStruct{
			Product: lists.Member.(string),
			Userid:  int64(lists.Score),
		}
		liststruct = append(liststruct, Collect)
	}
	return &storerpc.CollectlistResponse{Collect: liststruct}, nil
}
